package com.fruitshop.service.impl;

import com.fruitshop.dto.BannerDTO;
import com.fruitshop.entity.Banner;
import com.fruitshop.mapper.BannerMapper;
import com.fruitshop.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 轮播图服务实现类
 */
@Service
public class BannerServiceImpl implements BannerService {
    
    @Autowired
    private BannerMapper bannerMapper;
    
    @Override
    public List<BannerDTO> getAllActiveBanners() {
        List<Banner> banners = bannerMapper.findAllActive();
        return banners.stream()
                .map(this::convertToDTO)
                .collect(Collectors.toList());
    }
    
    /**
     * 将Banner实体转换为DTO
     */
    private BannerDTO convertToDTO(Banner banner) {
        BannerDTO dto = new BannerDTO();
        dto.setId(banner.getId());
        dto.setImage_url(banner.getImageUrl());
        dto.setTitle(banner.getTitle());
        dto.setLink(banner.getLink());
        return dto;
    }
} 